package euler.helpers;

import java.math.BigInteger;
import java.util.Iterator;

import org.jlambda.functions.Fun2;
import org.jlambda.list.List;
import org.jlambda.listFunctions.ListFun1;

public class BigIntMath {


	public static final class ToBigInt extends ListFun1<Iterable<String>, BigInteger>{

		Iterator<String> itr =null;
		
		@Override
		protected void create(List<BigInteger> list, Iterable<String> p1) {
			itr = p1.iterator();
		}

		public BigInteger getNext() {
			if (itr.hasNext()){
				return new BigInteger(itr.next());
			}
			EOL();
			return null;
		}
		
	};
	
	public static final ListFun1<Iterable<String>, BigInteger> toBigInt =new ToBigInt();
	
	public static Fun2<BigInteger, BigInteger, BigInteger> addB =new Fun2<BigInteger, BigInteger, BigInteger>() {
		@Override
		public BigInteger apply(BigInteger p1, BigInteger p2) {
			return p1.add(p2);
		}

	};
	
	public static Fun2<BigInteger, BigInteger, Boolean> multipleOfB =new Fun2<BigInteger, BigInteger, Boolean>() {
		@Override
		public Boolean apply(BigInteger p1, BigInteger p2) {
			if (p2.divideAndRemainder(p1)[1].shortValue()==0) return true;
			return false;
		}

	};
	
	public static Fun2<BigInteger, BigInteger, Boolean> lessthanB =new Fun2<BigInteger, BigInteger, Boolean>() {
		@Override
		public Boolean apply(BigInteger p1, BigInteger p2) {
			if (p1.compareTo(p2)<0) return true;
			return false;
		}

	};
	
	public static final Fun2<Long, Long, Boolean> lessThanL = new Fun2<Long, Long, Boolean>() {
		@Override
		public Boolean apply(Long p1, Long p2) {
			if (p1 <p2 ) {
				return true;
			}
			return false;
		}
	};
	public static final Fun2<Integer, Integer, Boolean> lessThanI = new Fun2<Integer, Integer, Boolean>() {
		@Override
		public Boolean apply(Integer p1, Integer p2) {
			if (p1 <p2 ) {
				return true;
			}
			return false;
		}
	};	
	public static Fun2<Long, Long, Long> addL =new Fun2<Long, Long, Long>() {
		@Override
		public Long apply(Long p1, Long p2) {
			return p1.longValue() + p2.longValue();
		}

	};
	public static Fun2<Number, Long, Long> addNtoL =new Fun2<Number, Long, Long>() {
		@Override
		public Long apply(Number p1, Long p2) {
			return p1.longValue() + p2.longValue();
		}

	};
	public static Fun2<Integer, Long, Long> addItoL =new Fun2<Integer, Long, Long>() {
		@Override
		public Long apply(Integer p1, Long p2) {
			return p1.longValue() + p2.longValue();
		}

	};
	public static Fun2<Long, Long, Boolean> multipleOfL =new Fun2<Long, Long, Boolean>() {
		@Override
		public Boolean apply(Long p1, Long p2) {
			if (p2.longValue()%p1.longValue()==0) return true;
			return false;
		}

	};
}
